/*
  File:    Endian.cpp
  Purpose: Provides functions for converting to little-endian 
           architectures, such as Sparc and PowerPC (Mac) 
		  machines.

  Contact: Paul Macklin
           pmacklin@math.uci.edu
		  http://math.uci.edu/~pmacklin
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>

using namespace std;

bool BigEndian( void )
{
 short word = 0x0001;
 if((*(char *)& word) != 0x01 )
 { return true; }
 return false;
}

double ReadDoubleOnBigEndianMachine( FILE* fp )
{
 double Output; 
 int i;
 for( i=0 ; i < 8 ; i++ )
 { fread( (char*) &Output+7-i, 1, 1, fp ); }
 return Output; 
}

bool WriteDoubleOnBigEndianMachine( FILE* fp , double Input )
{
 int i;
 for( i=0 ; i < 8 ; i++ )
 { fwrite( (char*) &Input+7-i, 1, 1, fp ); }
 return true; 
}
